﻿/*
 * Created by SharpDevelop.
 * User: IEscarro
 * Date: 9/4/2009
 * Time: 9:26 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;
using PilotFish.Model;
using PilotFish.Util;

namespace PilotFish.Gui
{
	/// <summary>
	/// Description of LoginForm.
	/// </summary>
	public partial class LoginForm : Form
	{
		public LoginForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
		}
		
		void ButtonOkClick(object sender, EventArgs e)
		{
			User u = SessionFacade.ReadUserByNameAndPassword(textBoxName.Text, textBoxPassword.Text);
			if (u == null) {
				MessageService.ShowWarning(
					"The use name or password you typed is incorrect. Please try again or contact your " + Environment.NewLine +
					"administrator for help." + Environment.NewLine + Environment.NewLine + 
					"Passwords are case-sensitive." + Environment.NewLine + Environment.NewLine +
					"For information about troubleshooting or resetting passwords, click Help."
				);
			} else {
				UserSingleton.Instance = u;
				ClinicSingleton.Instance = SessionFacade.ReadClinicByPk(1);
				DialogResult = DialogResult.OK;
				Close();
			}
		}
	}
}
